package com.hirsi.core.vo.result;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

@Data
@ApiSort(2)
@ApiModel(value = "分页查询返回", parent = ResponseResult.class)
public class PageResult<T> {

    @ApiModelProperty("当前页码")
    private Long current;

    @ApiModelProperty(value = "每页数量", position = 1)
    private Long size;

    @ApiModelProperty(value = "总页数", position = 2)
    private Long pages;

    @ApiModelProperty(value = "总数量", position = 3)
    private Long total;

    @ApiModelProperty(value = "数据集合", position = 4)
    private List<T> rows;

    public static <T> PageResult<T> parse(IPage<T> iPage) {
        return new PageResult<T>(iPage.getCurrent(), iPage.getSize(), iPage.getPages(), iPage.getTotal(), iPage.getRecords());
    }

    private PageResult(){}

    public PageResult(Long current, Long size, List<T> rows) {
        this.current = current;
        this.size = size;
        this.rows = rows;
    }

    public PageResult(Long current, Long size, Long pages, Long total) {
        this.current = current;
        this.size = size;
        this.pages = pages;
        this.total = total;
    }

    public PageResult(Long current, Long size, Long pages, Long total, List<T> rows) {
        this.current = current;
        this.size = size;
        this.pages = pages;
        this.total = total;
        this.rows = rows;
    }
}
